{% extends "base.html" %}
{% load i18n plmapp_tags humanize %}

{% block css %}
    <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}css/timeline.css" />
{% endblock %}

{% block content %}

    {% if not restricted %}
        <div>
            <div class="timeline open" >
                <h3 class="hplm" data-toggle="collapse" data-target="#last-objects">
                    <span class="expander"></span>{% trans "Last edited objects" %}
                </h3>

                <div class="objects tb-collapse tb-in" id="last-objects">

                    <dl>
                        {% for histo in last_edited_objects %}
                            {% with histo.plmobject|is_readable:request.user as item_readable %}
                                <dt class="changeset">
                                <span class="time">
                                    {{ histo.date|naturalday|capfirst }} - {{histo.date|date:"G:i"}}
                                </span>
                                <span class="action"> {{histo.action}} </span>
                                {% with histo.plmobject as plmobject %}
                                    <span class="type">{{ plmobject.type }}</span>
                                    {% if item_readable %}
                                        {% spaceless %}
                                            <a href="{{ plmobject.plmobject_url }}">
                                                <span class="reference">{{ plmobject.reference }}</span>
                                            </a>
                                        {% endspaceless %}
                                    {% else %}
                                        <span class="reference">{{ plmobject.reference }}</span>
                                    {% endif%}
                                    <span class="revision">{{ plmobject.revision }}</span>
                                {% endwith %}
                                </dt>
                                <dd>
                                {% if item_readable %}
                                    <div class="details">
                                        {{ histo.details|linebreaks }}
                                    </div>
                                {% endif %}
                                </dd>
                            {% endwith %}
                        {% endfor %}
                    </dl>
                </div>
            </div>
        </div>
    {% endif %}
    {% regroup object_user_link by role as links %}

    {% for group in links %}
        <div class="timeline">
            <h3 class="hplm collapsed" data-toggle="collapse" data-target="#group-{{ group.grouper }}">
                <span class="expander"></span>{% trans group.grouper|capfirst %}
            </h3>

            <div class="tb-collapse" id="group-{{ group.grouper }}">
            {% regroup group.list by plmobject__type as groups %}

            {% for gp in groups %}

                <div class="objects">

                    <h4 class="hplm">{{ gp.grouper }} </h4>
                    <div class="objects_inner">
                        <ul>
                            {% for link in gp.list %}
                                <li>
                                {% spaceless %}
                                    <a href="/object/{{link.plmobject__type|urlencode }}/{{link.plmobject__reference|urlencode }}/{{link.plmobject__revision|urlencode }}/{% if restricted %}public/{% endif %}">
                                        <span class="reference">{{link.plmobject__reference}}</span>
                                    </a>
                                {% endspaceless %}
                                <span class="revision">{{link.plmobject__revision}}</span>
                                <span class="name">{{link.plmobject__name}}</span>
                                </li>
                            {% endfor %}
                        </ul>
                        <br />
                    </div>
                </div>
            {% endfor %}
                </div>
        </div>

    {% endfor %}

{% endblock %}


